package com.example.demo.service;

import com.example.demo.config.TargetDataSource;
import com.example.demo.entity.Person;
import com.example.demo.repository.PersonRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by pengwan on 2017/8/1.
 */
@Service
public class PersonService {
    @Autowired
    private PersonRepository personRepository;

    @TargetDataSource(name="Master")
    public Person save(Person person){
        return this.personRepository.save(person);
    }

    @TargetDataSource(name="Slave")
    public List<Person> findAll(){
        return this.personRepository.findAll();
    }
}
